﻿using UnityEngine;
using System;
using System.Collections;

namespace Hont.UMotionGraph
{
    public class MGRandomEffector : MoGraphEffector
    {
        [Serializable]
        public class GeneralSetting
        {
            public enum ModeEnum { Random, SinAnimation };
            public ModeEnum mode;
            public float Amp = 1f;
            public float Freq = 1f;
            public float BaseValue = 1f;
        }

        public GeneralSetting generalSetting;
        public float force = 1;
        float mAdditiveValue;
        Vector3[] scalePositionArr;


        public override void Init(IMoGraphContainer container)
        {
            base.Init(container);

            scalePositionArr = new Vector3[container.Count];

            for (int i = 0; i < scalePositionArr.Length; i++)
            {
                scalePositionArr[i] = UnityEngine.Random.insideUnitSphere;
            }
        }

        public override Vector3 Execute(int inx, Vector3 inValue, float fallOffProportion)
        {
            if (generalSetting.mode == GeneralSetting.ModeEnum.SinAnimation)
            {
                mAdditiveValue = generalSetting.BaseValue
                    + Mathf.Sin(Time.time * generalSetting.Freq) * generalSetting.Amp;
            }
            else
            {
                mAdditiveValue = 1f;
            }

            return inValue + scalePositionArr[inx] * (force * fallOffProportion) * mAdditiveValue;
        }
    }
}
